package com.beagle.njddapp.ui.activity.dirver;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.bean.dirver.OilOrderState;
import com.beagle.njddapp.bean.owner.DIrverOrderBean;
import com.beagle.njddapp.ui.adapter.NjDirverListAdapter;
import com.beagle.njddapp.ui.adapter.inter.RecyclerViewItemClickLisenter;
import com.beagle.njddapp.ui.presenter.DirverDetailPresenter;
import com.beagle.njddapp.ui.view.DirverDetailView;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.blankj.utilcode.util.ToastUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-21 13:32
 * 农机驾驶员-订单
 */
public class DirverOrderActivity extends BaseMvpActivity<DirverDetailView, DirverDetailPresenter> implements DirverDetailView, RecyclerViewItemClickLisenter<DIrverOrderBean>, NjDirverListAdapter.DirverOrderCzCallBack {



    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.smartrefreshLayout)
    SmartRefreshLayout refreshLayout;

    @BindView(R.id.common_recyclerview)
    RecyclerView recyclerView;
    private NjDirverListAdapter njDirverListAdapter;
    private List<DIrverOrderBean> orderBeanList;

    @Override
    public int getLayoutId() {
        return R.layout.activity_oil_orders;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this, Color.WHITE);
        StatusBarUtil.darkMode(this);
        tvTitle.setText("我的订单");
        container.setBackgroundColor(Color.WHITE);
        StatusBarUtil.setPaddingSmart(this, container);
        presenter.getList();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        orderBeanList=new ArrayList<>();
        njDirverListAdapter=new NjDirverListAdapter(orderBeanList,this);
        njDirverListAdapter.setDirverOrderCzCallBack(this);
        njDirverListAdapter.setOnItemClickLisenter(this);
        recyclerView.setAdapter(njDirverListAdapter);
        refreshLayout.setEnableRefresh(true);
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                presenter.getList();
            }
        });

    }

    @Override
    public DirverDetailView getMvpView() {
        return this;
    }

    @Override
    public DirverDetailPresenter createPresenter() {
        return new DirverDetailPresenter();
    }

    @Override
    public void onError(String message) {
        refreshLayout.finishRefresh();
        ToastUtils.showShort(message);
    }

    @Override
    public void showOrderList(List<DIrverOrderBean> results) {
        refreshLayout.finishRefresh();
        orderBeanList.clear();
        orderBeanList.addAll(results);
        njDirverListAdapter.notifyDataSetChanged();
    }

    @OnClick({R.id.common_back_iv})
    public void onMyClick(View view){
        switch (view.getId()){
            case R.id.common_back_iv:
                onBackPressed();
                break;
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        presenter.getList();
    }

    @Override
    public void updateSuccess() {
        ToastUtils.showShort("确认成功");
        presenter.getList();
    }

    @Override
    public void meshStatus(OilOrderState o) {

    }

    @Override
    public void SqSuccess() {

    }

    @Override
    public void showUpdateSuccess() {

    }

    @Override
    public void giveBackSuccess() {

    }

    @Override
    public void onItemClickLisenter(DIrverOrderBean dIrverOrderBean) {
        startActivityForResult(new Intent(this, DirverOrderDetailActivity.class).putExtra("data",dIrverOrderBean).putExtra("type",2),314);
    }

    @Override
    public void caozuo(DIrverOrderBean dIrverOrderBean) {
        if (3==dIrverOrderBean.getOrderStatus()){
            dIrverOrderBean.setOrderStatus(4);
            presenter.updateFindDriverOrder(dIrverOrderBean);
        }
    }
}
